package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.NewsDao;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class NewsImpl implements NewsDao {
    @Override
    public List<NewsModel> getNewsModelListFroHomePage() {
        String sql="select * from news where where_show=1 order by sort desc";
        List<NewsModel> list=new ArrayList<>();
        ResultSet resultSet= JDBC.getRs(sql);
        try {
            while (resultSet.next()){
                NewsModel model=new NewsModel();
                model.setId(resultSet.getInt("id"));
                model.setTitle(resultSet.getString("title"));
                model.setContent(resultSet.getString("content"));
                list.add(model);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
